#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input_file = sys.argv[1]
output_file = sys.argv[2]
messages = {}
notes = []
with open(input_file, 'r', newline='') as text_f:
    for row in text_f:
        if '[Note]' in row:
            row_list = row.split(' ', 4)
            day = row_list[0].strip()
            note = row_list[4].strip('\n').strip()
            if note not in notes:
                notes.append(note)
            if day not in messages:
                messages[day] = {}
            if note not in messages[day]:
                messages[day][note] = 1
            else:
                messages[day][note] += 1
filewriter = open(output_file, 'w', newline='')
header = ['Date']
header.extend(notes)
header_str = ','.join(map(str, header)) + '\n'
print(header_str)
filewriter.write(header_str)
for day, day_value in messages.items():
    row_list = []
    row_list.append(day)
    for index in range(len(notes)):
        if notes[index] in day_value.keys():
            row_list.append(str(day_value[notes[index]]))
        else:
            row_list.append('0')
    row_str = ','.join(map(str, row_list)) + '\n'
    filewriter.write(row_str)
filewriter.close()
